using System;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;

namespace Microsoft.Practices.Repository.Configuration.Design
{
    class RepositoryFactorySectionNodeBuilder : NodeBuilder
    {
        private readonly RepositoryFactorySection section;

        public RepositoryFactorySectionNodeBuilder(IServiceProvider serviceProvider, RepositoryFactorySection section)
            : base(serviceProvider)
        {
            this.section = section;
        }

        public RepositoryFactorySectionNode Build()
        {
            RepositoryFactorySectionNode node = new RepositoryFactorySectionNode();
            RepositoryCollectionNode repositoriesNode = new RepositoryCollectionNode();
            node.AddNode(repositoriesNode);

            foreach (RepositoryElement repositoryElement in section.Repositories)
            {
                repositoriesNode.AddNode(new RepositoryNode(repositoryElement.InterfaceType, repositoryElement.RepositoryType));
            }

            return node;

        }
    }
}
